﻿Public Class fMunicipios
    Dim daMuni As lbGlobalcom.dsGlobalTableAdapters.GLO_MUNICIPIOSTableAdapter
    Private Sub btnCargaMunicipios_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargaMunicipios.Click
        Try
            If DsGlobal.GLO_MUNICIPIOS.GetChanges IsNot Nothing Then
                GLO_MUNICIPIOSBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por slavar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daMuni.Update(DsGlobal.GLO_MUNICIPIOS)
                End If
            End If
            daMuni.Fill(DsGlobal.GLO_MUNICIPIOS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fMunicipios_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If DsGlobal.GLO_MUNICIPIOS.GetChanges IsNot Nothing Then
                GLO_MUNICIPIOSBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por slavar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daMuni.Update(DsGlobal.GLO_MUNICIPIOS)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fMunicipios_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daMuni = New lbGlobalcom.dsGlobalTableAdapters.GLO_MUNICIPIOSTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub GLO_MUNICIPIOSBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_MUNICIPIOSBindingNavigatorSaveItem.Click
        Try
            daMuni.Update(DsGlobal.GLO_MUNICIPIOS)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                GLO_MUNICIPIOSBindingSource.Remove(GLO_MUNICIPIOSBindingSource.Current)
                daMuni.Update(DsGlobal.GLO_MUNICIPIOS)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub GLO_MUNICIPIOSDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles GLO_MUNICIPIOSDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub GLO_MUNICIPIOSDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles GLO_MUNICIPIOSDataGridView.UserDeletedRow
        Try
            daMuni.Update(DsGlobal.GLO_MUNICIPIOS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub GLO_MUNICIPIOSDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles GLO_MUNICIPIOSDataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub
End Class